package com.suny;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 顶层接口测试
 *
 * @author Sunny
 * @date 2019/10/29 下午5:52
 */
public class ExecutorServiceTest {

    public static void main(String[] args) {
        test();
    }

    public static void test() {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 15, 20, TimeUnit.SECONDS, new LinkedBlockingQueue<>());

        for (int i = 0; i < 100; i++) {
            executor.execute(() -> System.out.println(Thread.currentThread().getName() + " test executor"));
        }

        executor.shutdown();

        try {
            if (!executor.awaitTermination(800, TimeUnit.MICROSECONDS)) {
                executor.shutdownNow();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
